import Home from '@/views/Home.vue'
const Login = () => import(/* webpackChunkName: 'login' */ '@/views/Login.vue')
const Reg = () => import(/* webpackChunkName: 'reg' */ '@/views/Reg.vue')
const Forget = () =>
  import(/* webpackChunkName: 'forget' */ '@/views/Forget.vue')
const Index = () =>
  import(/* webpackChunkName: 'index' */ '@/views/channels/Index.vue')
const Template1 = () =>
  import(/* webpackChunkName: 'template1' */ '@/views/channels/Template1.vue')
const Center = () =>
  import(/* webpackChunkName: 'center' */ '@/views/Center.vue')
const UserCenter = () =>
  import(/* webpackChunkName: 'user-center' */ '@/components/user/Center.vue')
const Settings = () =>
  import(/* webpackChunkName: 'settings' */ '@/components/user/Settings.vue')
const Posts = () =>
  import(/* webpackChunkName: 'user-post' */ '@/components/user/Posts.vue')
const Msg = () =>
  import(/* webpackChunkName: 'user-msg' */ '@/components/user/Msg.vue')
const Others = () =>
  import(/* webpackChunkName: 'othres' */ '@/components/user/Others.vue')
const User = () =>
  import(/* webpackChunkName: 'home' */ '@/views/User.vue')
const Chat = () =>
  import(/* webpackChunkName: 'chat' */ '@/views/Chat.vue')
const MyInfo = () =>
  import(/* webpackChunkName: 'info' */ '@/components/user/common/MyInfo.vue')
const PicUpload = () =>
  import(/* webpackChunkName: 'uploadpic' */ '@/components/user/common/PicUpload.vue')
const Passwd = () =>
  import(/* webpackChunkName: 'password' */ '@/components/user/common/Passwd.vue')
const MyPost = () =>
  import(/* webpackChunkName: 'mypost' */ '@/components/user/common/MyPost.vue')
const MyCollection = () =>
  import(/* webpackChunkName: 'mycollection' */ '@/components/user/common/MyCollection.vue')
const NotFound = () =>
  import(/* webpackChunkName: 'NotFound' */ '@/views/NotFound.vue')
const Confirm = () =>
  import(/* webpackChunkName: 'Confirm' */ '@/views/Confirm.vue')
const Reset = () =>
  import(/* webpackChunkName: 'Reset' */ '@/views/Reset.vue')
const Add = () =>
  import(/* webpackChunkName: 'Add' */ '@/components/contents/Add.vue')
const Add2 = () =>
  import(/* webpackChunkName: 'Add' */ '@/components/contents/Add2.vue')
const Edit = () =>
  import(/* webpackChunkName: 'NotFound' */ '@/components/contents/Edit.vue')
const Detail = () =>
  import(/* webpackChunkName: 'NotFound' */ '@/components/contents/Detail.vue')

export const routes = [{
  path: '/',
  component: Home,
  children: [
    {
      path: '',
      name: 'index',
      component: Index
    },
    {
      path: '/index/:catalog',
      name: 'catalog',
      component: Template1
    }
  ]
},
{
  path: '/login',
  name: 'login',
  component: Login
},
{
  path: '/reset',
  name: 'reset',
  component: Reset
},
{
  path: '/confirm',
  name: 'confirm',
  component: Confirm
},
{
  path: '/reg',
  name: 'reg',
  component: Reg,
  beforeEnter: (to, from, next) => {
    if (from.name === 'login') {
      next()
    } else {
      next('/login')
    }
  }
},
{
  path: '/forget',
  name: 'forget',
  component: Forget
},
{
  path: "/add",
  name: 'add',
  component: Add,
  meta: {
    requiresAuth: true
  }
},
{
  path: "/add2",
  name: 'add2',
  component: Add2
},
{
  path: '/edit/:tid',
  props: true,
  name: 'edit',
  component: Edit,
  meta: {
    requiresAuth: true
  },
  beforeEnter: (to, from, next) => {
    if (['detail', 'mypost'].indexOf(from.name) !== -1 && to.params.page && to.params.page.isEnd === '0') {
      next()
    } else {
      const editData = localStorage.getItem('editData')
      if (editData && editData !== '') {
        const editObj = JSON.parse(editData)
        if (editObj.isEnd === '0') {
          next()
        } else {
          next('/')
        }
      } else {
        next('/')
      }
    }
  }
},
{
  path: '/user/:uid',
  name: 'home',
  props: true,
  component: User
},
{
  path: '/chat/:uid',
  name: 'chat',
  props: true,
  component: Chat
},
{
  path: '/detail/:tid',
  name: 'detail',
  props: true,
  component: Detail
},
{
  path: '/center',
  component: Center,
  linkActiveClass: 'layui-this',
  meta: { requiresAuth: true },
  children: [
    {
      path: '',
      name: 'center',
      component: UserCenter
    },
    {
      path: 'set',
      component: Settings,
      children: [
        {
          path: '',
          name: 'info',
          component: MyInfo
        },
        {
          path: 'pic',
          name: 'pic',
          component: PicUpload
        },
        {
          path: 'passwd',
          name: 'passwd',
          component: Passwd
        }
      ]
    },
    {
      path: 'posts',
      component: Posts,
      children: [
        {
          path: '',
          name: 'mypost',
          component: MyPost
        },
        {
          path: 'mycollection',
          name: 'mycollection',
          component: MyCollection
        }
      ]
    },
    {
      path: 'msg',
      name: 'msg',
      component: Msg
    },
    {
      path: 'others',
      name: 'others',
      component: Others
    }
  ]
}, {
  path: '/404',
  component: NotFound
}, {
  path: '*',
  redirect: '/404'
}]

